<template>
	<view class="content-header-f">
		<view class="header" v-if="userInfo!=null">
			<view class="top132"></view>
			<view class="flex-column">
				<view class="flex-row flex-content-center">
					<view class="header-img">
						<image @tap="changeTx" :src="userInfo.avatar?$utils.cdnImg(userInfo.avatar):`../../static/user/xj.png`" mode="scaleToFill"></image>
					</view>
				</view>
				<view class="header-txt-1">请上传用户头像</view>
				<view class="top49"></view>
				<view class="form-txt-1 flex-row">
					<view>昵称</view>
					<input type="text" v-model="userInfo.nickname" placeholder="请输入您的昵称" placeholder-class="input-p"/>
				</view>
				<view class="form-txt-1 flex-row">
					<view>密码</view>
					<input type="password" v-model="from.password" placeholder="请设置您的登录密码" placeholder-class="input-p"/>
				</view>
				<view class="queren" @tap="submit">确认</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				from:{
					nickname:"",
					password:"",
					avatar:""
				}
			}
		},
		computed:{
			userInfo(){
				return this.$store.state.user.userInfo;
			}
		},
		onLoad() {
			this.$store.dispatch("getUserInfo");
		},
		methods:{
			changeTx(){
				let that = this;
				this.$utils.UploadImages("/api/common/upload",(res)=>{
					res = JSON.parse(res)
					// console.log(res);
					if(res.code==1){
						that.userInfo.avatar = res.data.url;
					}
					
				})
			},
			submit(){
				let data = {
					nickname:this.userInfo.nickname,
					avatar:this.userInfo.avatar,
					password:this.from.password
				}
				let that = this;
				this.$api.changeUser(data).then(res=>{
					that.$store.dispatch("getUserInfo");
					that.$utils.showMessage("修改成功",()=>{
						uni.navigateBack();
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.queren{
		width: 690rpx;
		height: 96rpx;
		background: $default-button-color;
		border-radius: 48rpx 48rpx 48rpx 48rpx;
		opacity: 1;
		text-align: center;
		line-height: 96rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: $default-button-foncolor;
		margin-top: 80rpx;
	}
	.input-p{
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
	}
	.top49{
		width: 100%;
		height: 49rpx;
	}
	.form-txt-1{
		width: 690rpx;
		height: 96rpx;
		background: #F6F6F6;
		border-radius: 48rpx 48rpx 48rpx 48rpx;
		opacity: 1;
		line-height: 96rpx;
		margin-top: 50rpx;
		>view:nth-child(1){
			font-size: 28rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #333333;
			margin-left: 50rpx;
		}
		input{
			height: 50rpx;
			margin-top: 15rpx;
			padding: 10rpx 0rpx 0rpx 68rpx;
		}
	}
	.header-txt-1{
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		text-align: center;
		margin-top: 30rpx;
	}
	.header-img{
		width: 168rpx;
		height: 168rpx;
		background: #F2F2F2;
		opacity: 1;
		border-radius: 84rpx;
		line-height: 168rpx;
		text-align: center;
		>image{
			width: 168rpx;
			height: 168rpx;
			border-radius: 84rpx;
		}
	}
	.top132{
		width: 100%;
		height: 132rpx;
	}
	.header{
		width: 690rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
	}
</style>